package com.dsp.soundscape.server;

import java.util.logging.Logger;

import javax.xml.bind.JAXBException;

import com.dsp.soundscape.config.filesystem.ConfigurationType;
import com.dsp.soundscape.model.VersionInfo;
import com.dsp.soundscape.util.ConfigLoader;

public class ConfigManager {
	private static Logger log = Logger.getLogger(ConfigManager.class.toString());

//	private static final String STREAMER_PATH = "streamer/";
	
	private VersionInfo version = new VersionInfo();
	
	private ConfigurationType configuration;

	private String pathroot = "";
	private String uriroot = "";
	
	public String getPrefix() {
		return uriroot;
	}

	public String getPathroot() {
		return pathroot;
	}
	
	public String getUriroot() {
		return uriroot;
	}

	public VersionInfo getVersion() {
		return version;
	}

	public ConfigurationType getConfiguration() {
		return configuration;
	}
	
	public ConfigManager() {
		try {
			configuration = ConfigLoader.load("soundscape.xml", "com.dsp.soundscape.config.filesystem");
			
			log.info("Starting Soundscape " + version.getFullVersion());
			
			if (configuration.getMusic().getRoot() != null) {
				pathroot = configuration.getMusic().getRoot().getDir();
				log.info("Music Root Path Enabled: " + pathroot);
				
				if (configuration.getMusic().getRoot().getApache() != null) {
					uriroot = configuration.getMusic().getRoot().getApache();
					log.info("Apache Root Path Enabled: " + uriroot);
				}
			}
					
		} catch (JAXBException ex) {
			throw new RuntimeException("Initialization Failed.", ex);
		}
	}
}
